import fs from "fs-extra";
import inquirer from "inquirer";
import { coverPrompt } from "../prompt/coverPrompt.js";

export const buildDownload = async function (filePath, problem) {
	return new Promise(async (resolve, reject) => {
		try {
			let res = {};
			let alreadyExist = fs.pathExistsSync(filePath);
			if (alreadyExist) {
				res = inquirer.prompt([coverPrompt].concat(problem));
			} else {
				res = inquirer.prompt(problem);
			}
			resolve(res);
		} catch (err) {
			reject(err);
		}
	});
};
